package com.caih.student.service.impl;

/*
@author zhouxiaojia
@create 2019-07-16 下午 03:33
*/

import com.caih.student.dao.StudentDao;
import com.caih.student.entity.Student;
import com.caih.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Optional;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao dao;

    @Override
    //查询全部
    public List<Student> queryAll() {
        List<Student> stuList = dao.findAll();
        return stuList;
    }

    @Override
    //查询通过id
    public Student queryById(Integer id) {
        Optional<Student> optStu = dao.findById(id);
        Student student = optStu.get();
        return student;
    }


    @Override
    //修改数据
    public Student update(Student student) {
        Student update = dao.save(student);
        return update;
    }

    @Override
    //删除数据
    public void delete(Integer id) {
        dao.deleteById(id);
    }

    @Override
    //插入数据
    public Student save(Student student) {
        Student save = dao.save(student);
        return save;
    }

    //查询通过学号
    @Override
    public Student queryByStuNo(String stuNo){
        Optional<Student> ops = dao.findByStuNo(stuNo);
        Student student = ops.get();
        return student;
    }

    @Override
    //插入
    public int searchStuNo(String stuNo){
        Optional<Student> opstu = dao.findByStuNo(stuNo);
        if(opstu.isPresent() == true){
            return 1;
        }
        else
            return 0;
    }


}




